<template>
  <div id="Government_drugs_review">
    <span>
      <img src="../assets/enterprise.png" alt="" class="bread-icon">
    </span>
    <!-- 面包屑导航 -->
    <el-breadcrumb style="display:inline-block">
      <el-breadcrumb-item>
        <span style="font-size:20px;">企业管理</span>
      </el-breadcrumb-item>
      <el-breadcrumb-item>
        <span style="font-size:15px;line-height:20px;">关联关系审核</span>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="content-wrap">
      <div class="topNav">
        <span class="navLeft">企业查询</span>
        <!-- <span class="navRight">
          <el-button size="small" @click="companySearch()">搜索</el-button>
        </span>
        <span class="navMid">
          <img class="icon-search" src="../assets/search.png" alt="">
          <el-input v-model="searchData" size="small" placeholder="请输入内容" class="searchInput"></el-input>
        </span> -->
      </div>

      <!-- 表格 -->
      <el-table :data="tableData" border class="table-common" :max-height="tableHeight">
        <el-table-column type="index" label="#">
        </el-table-column>
        <el-table-column prop="enterprise" label="申请企业">
        </el-table-column>
        <el-table-column prop="relation_enterprise" label="关联企业">
        </el-table-column>
        <el-table-column prop="apply_date" label="申请时间">
        </el-table-column>
        <el-table-column label="关联关系">
          <template slot-scope="scope">
            <span>下游企业</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100">
          <template slot-scope="scope">
            <el-button v-if="scope.row.is_verified === true" type="primary" plain size="mini" disabled>已审核</el-button>
            <el-button v-else type="danger" plain size="mini" disabled>未审核</el-button>
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="showForm(scope.row)" type="info" plain size="mini">查看详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>

    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        dialogTableVisible: false,
        dialogFormVisible: false,
        dialogDrugsVisible: false,
        dialogLinkVisible: false,
        tabPosition: 'left',
        setColumnsShow: false,
        isIndeterminate: true,
        checkAll: false,
        adminId: '',
        enterprise: '',
        adminToken: '',
        searchData: '',
        tableData: [{}],
        tableHeight: '',
        gridData: [{}],
        base_info: {},
        drugsList: [],
        formLabelWidth: '150px',
        link_info: {
          id: '',
          base_info: '',
          down_relations: [],
          up_relations: []
        },
      }
    },
    methods: {
      companySearch() {
        if (this.searchData != '') {
          this.$http({
            url: '/enterprise/relations-verify/?search=' + this.searchData + '&is_verified=false',
            method: 'get',
            headers: {
              'Authorization': 'Token ' + this.adminToken
            },
          }).then(
            response => {
              this.tableData = []
              this.tableData = response.data.results
              console.log(this.tableData)
              this.$message({
                message: '查询成功',
                showClose: true,
                type: 'success'
              });
            }
          ).catch(error => {
            console.log(error.response)
            if (error.response.status == 401) {
              this.$message({
                message: error.response.data.detail,
                type: 'warning'
              })
              this.$router.push({
                path: '/login'
              });
            } else if (error.response.status == 400) {
              this.$message({
                message: 'error400',
                type: 'error'
              })
            } else {
              this.$message({
                message: error.response.data.detail,
                type: 'error'
              })
            }
            console.log(error);
          });
        } else {
          this.$http({
            url: '/enterprise/relations-verify/',
            // url: '/drugs/'+adminId +'/',
            method: 'get',
            headers: {
              'Authorization': 'Token ' + this.adminToken
            },
            data: {
              page: 1,
              form: '',
              enterprise_id: this.adminId,
              search: '',
              ordering: ''
            }
          }).then(
            response => {
              //success
              console.log(response)
              this.tableData = [];
              this.tableData = response.data.results
              console.log(this.tableData)
            },
            response => {
              //error
              console.log(response)
              //   this.$message({
              //   message: response.data.detail,
              //   type: 'warning'
              // });
            }
          )
        }
      },
      showForm(row) {
        console.log(row)
        this.base_info = row.base_info
        this.dialogTableVisible = true
      },
      showLinkForm(row) {
        console.log(row)
        this.$http({
          url: '/enterprise/?search=' + row.base_info,
          method: 'get',
          headers: {
            'Authorization': 'Token ' + this.adminToken
          },
        }).then(
          response => {
            this.base_info = response.data.results[0].base_info
            console.log(this.base_info)
            this.dialogTableVisible = true
            this.$message({
              message: '查询成功',
              showClose: true,
              type: 'success'
            });
          }
        ).catch(error => {
          console.log(error.response)
          if (error.response.status == 401) {
            this.$message({
              message: error.response.data.detail,
              type: 'warning'
            })
            this.$router.push({
              path: '/login'
            });
          } else if (error.response.status == 400) {
            this.$message({
              message: 'error400',
              type: 'error'
            })
          } else {
            this.$message({
              message: error.response.data.detail,
              type: 'error'
            })
          }
          console.log(error);
        });

      },
      changeForm(row) {
        this.dialogFormVisible = true
        this.formData = row;
        console.log(this.formData);
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      handleCheckAllChange(val) {
        this.columns = val ? headerOptions : [];
        this.isIndeterminate = false;
      },
      handleCheckedHeaderChange(value) {
        let checkedCount = value.length;
        this.checkAll = checkedCount === this.columnsSelect.length;
        this.isIndeterminate = checkedCount > 0 && checkedCount < this.columnsSelect.length;
        console.log(this.columns)
      },
    },

    mounted() {
      this.adminId = this.$store.getters.getInfo.id
      this.adminToken = this.$store.getters.getInfo.token
      this.enterprise = this.$store.getters.getInfo.enterprise
      this.tableHeight = document.getElementsByClassName('table-common')[0].parentNode.clientHeight - 112
      if (localStorage.getItem('GovernmentCompanyReviewColumns')) {
        this.columns = JSON.parse(localStorage.getItem('GovernmentCompanyReviewColumns')).colums
      }
      this.$http({
        url: './relation-apply/',
        method: 'get',
        headers: {
          'Authorization': 'Token ' + this.adminToken
        },
      }).then(response => {
        console.log(response)
        this.tableData = response.data.results
      }).catch(error => {
        console.log(error.response)
        if (error.response.status == 401) {
          this.$message({
            message: error.response.data.detail,
            type: 'warning'
          })
          this.$router.push({
            path: '/login'
          });
        } else if (error.response.status == 400) {
          this.$message({
            message: 'error400',
            type: 'error'
          })
        } else {
          this.$message({
            message: error.response.data.detail,
            type: 'error'
          })
        }
        console.log(error);
      });
    }
  }

</script>

<style scoped>
  #Government_drugs_review>>>.el-dialog {
    max-width: 900px;
    max-height: 600px;
    overflow: scroll;
  }

  #Government_drugs_review>>>.el-input {
    width: 220px;
  }

  /* #Company_medcode >>> .el-dialog input{
    width: 250px;
} */

</style>
